package com.jinmdz.fmis.mapper.mapper.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import com.jinmdz.fmis.mapper.entity.FuneralDeadEntity;

/**
 * 逝者表Provider
 * 
 * @author generator
 * @date 2020-08-23 18:11
 */
public class FuneralDeadProvider {

    /**
     * 增加FuneralDead
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String insertFuneralDead(@Param("entity") FuneralDeadEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" funeral_dead ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" business_code ", " #{entity.businessCode,jdbcType=VARCHAR} ");
                VALUES(" dead_name ", " #{entity.deadName,jdbcType=VARCHAR} ");
                VALUES(" dead_gender_code ", " #{entity.deadGenderCode,jdbcType=SMALLINT} ");
                VALUES(" dead_nation_code ", " #{entity.deadNationCode,jdbcType=SMALLINT} ");
                VALUES(" dead_age_type_code ", " #{entity.deadAgeTypeCode,jdbcType=SMALLINT} ");
                VALUES(" dead_age ", " #{entity.deadAge,jdbcType=VARCHAR} ");
                VALUES(" birth_date ", " #{entity.birthDate,jdbcType=DATE} ");
                VALUES(" certificate_type_code ", " #{entity.certificateTypeCode,jdbcType=SMALLINT} ");
                VALUES(" certificate_no ", " #{entity.certificateNo,jdbcType=VARCHAR} ");
                VALUES(" dead_name_unison ", " #{entity.deadNameUnison,jdbcType=VARCHAR} ");
                VALUES(" dead_name_abbr ", " #{entity.deadNameAbbr,jdbcType=VARCHAR} ");
                VALUES(" death_date ", " #{entity.deathDate,jdbcType=DATE} ");
                VALUES(" death_cause ", " #{entity.deathCause,jdbcType=VARCHAR} ");
                VALUES(" ash_handle_type_code ", " #{entity.ashHandleTypeCode,jdbcType=SMALLINT} ");
                VALUES(" cremation_type_code ", " #{entity.cremationTypeCode,jdbcType=SMALLINT} ");
                VALUES(" remains_state_code ", " #{entity.remainsStateCode,jdbcType=SMALLINT} ");
                VALUES(" country_code ", " #{entity.countryCode,jdbcType=SMALLINT} ");
                VALUES(" province_id ", " #{entity.provinceId,jdbcType=INTEGER} ");
                VALUES(" city_id ", " #{entity.cityId,jdbcType=INTEGER} ");
                VALUES(" county_id ", " #{entity.countyId,jdbcType=INTEGER} ");
                VALUES(" town_id ", " #{entity.townId,jdbcType=INTEGER} ");
                VALUES(" village_id ", " #{entity.villageId,jdbcType=INTEGER} ");
                VALUES(" province_city_county_full_name ", " #{entity.provinceCityCountyFullName,jdbcType=VARCHAR} ");
                VALUES(" household_registration_place ", " #{entity.householdRegistrationPlace,jdbcType=VARCHAR} ");

                if (entity.getAsLocal() != null) {
                    VALUES(" as_local ", " #{entity.asLocal,jdbcType=TINYINT} ");
                }

                VALUES(" before_death_address ", " #{entity.beforeDeathAddress,jdbcType=VARCHAR} ");
                VALUES(" benefit_district_code ", " #{entity.benefitDistrictCode,jdbcType=SMALLINT} ");
                VALUES(" exemption_type_code ", " #{entity.exemptionTypeCode,jdbcType=SMALLINT} ");
                VALUES(" death_certificate_no ", " #{entity.deathCertificateNo,jdbcType=VARCHAR} ");
                VALUES(" death_certificate_unit ", " #{entity.deathCertificateUnit,jdbcType=VARCHAR} ");
                VALUES(" funeral_certificate_unit ", " #{entity.funeralCertificateUnit,jdbcType=VARCHAR} ");
                VALUES(" transport_place ", " #{entity.transportPlace,jdbcType=VARCHAR} ");

                if (entity.getAsArrived() != null) {
                    VALUES(" as_arrived ", " #{entity.asArrived,jdbcType=TINYINT} ");
                }

                VALUES(" arrived_time ", " #{entity.arrivedTime,jdbcType=TIMESTAMP} ");
                VALUES(" negotiator_user_id ", " #{entity.negotiatorUserId,jdbcType=INTEGER} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" whereabout_type_code ", " #{entity.whereaboutTypeCode,jdbcType=SMALLINT} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改FuneralDead
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String updateFuneralDead(@Param("entity") FuneralDeadEntity entity) {
        return new SQL() {
            {
                UPDATE(" funeral_dead ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                SET(" dead_name = #{entity.deadName,jdbcType=VARCHAR} ");
                SET(" dead_gender_code = #{entity.deadGenderCode,jdbcType=SMALLINT} ");
                SET(" dead_nation_code = #{entity.deadNationCode,jdbcType=SMALLINT} ");
                SET(" dead_age_type_code = #{entity.deadAgeTypeCode,jdbcType=SMALLINT} ");
                SET(" dead_age = #{entity.deadAge,jdbcType=VARCHAR} ");
                SET(" birth_date = #{entity.birthDate,jdbcType=DATE} ");
                SET(" certificate_type_code = #{entity.certificateTypeCode,jdbcType=SMALLINT} ");
                SET(" certificate_no = #{entity.certificateNo,jdbcType=VARCHAR} ");
                SET(" dead_name_unison = #{entity.deadNameUnison,jdbcType=VARCHAR} ");
                SET(" dead_name_abbr = #{entity.deadNameAbbr,jdbcType=VARCHAR} ");
                SET(" death_date = #{entity.deathDate,jdbcType=DATE} ");
                SET(" death_cause = #{entity.deathCause,jdbcType=VARCHAR} ");
                SET(" ash_handle_type_code = #{entity.ashHandleTypeCode,jdbcType=SMALLINT} ");
                SET(" cremation_type_code = #{entity.cremationTypeCode,jdbcType=SMALLINT} ");
                SET(" remains_state_code = #{entity.remainsStateCode,jdbcType=SMALLINT} ");
                SET(" country_code = #{entity.countryCode,jdbcType=SMALLINT} ");
                SET(" province_id = #{entity.provinceId,jdbcType=INTEGER} ");
                SET(" city_id = #{entity.cityId,jdbcType=INTEGER} ");
                SET(" county_id = #{entity.countyId,jdbcType=INTEGER} ");
                SET(" town_id = #{entity.townId,jdbcType=INTEGER} ");
                SET(" village_id = #{entity.villageId,jdbcType=INTEGER} ");
                SET(" province_city_county_full_name = #{entity.provinceCityCountyFullName,jdbcType=VARCHAR} ");
                SET(" household_registration_place = #{entity.householdRegistrationPlace,jdbcType=VARCHAR} ");

                if (entity.getAsLocal() != null) {
                    SET(" as_local = #{entity.asLocal,jdbcType=TINYINT} ");
                }

                SET(" before_death_address = #{entity.beforeDeathAddress,jdbcType=VARCHAR} ");
                SET(" benefit_district_code = #{entity.benefitDistrictCode,jdbcType=SMALLINT} ");
                SET(" exemption_type_code = #{entity.exemptionTypeCode,jdbcType=SMALLINT} ");
                SET(" death_certificate_no = #{entity.deathCertificateNo,jdbcType=VARCHAR} ");
                SET(" death_certificate_unit = #{entity.deathCertificateUnit,jdbcType=VARCHAR} ");
                SET(" funeral_certificate_unit = #{entity.funeralCertificateUnit,jdbcType=VARCHAR} ");
                SET(" transport_place = #{entity.transportPlace,jdbcType=VARCHAR} ");

                if (entity.getAsArrived() != null) {
                    SET(" as_arrived = #{entity.asArrived,jdbcType=TINYINT} ");
                }

                SET(" arrived_time = #{entity.arrivedTime,jdbcType=TIMESTAMP} ");
                SET(" negotiator_user_id = #{entity.negotiatorUserId,jdbcType=INTEGER} ");
                SET(" remark = #{entity.remark} ");
                SET(" whereabout_type_code = #{entity.whereaboutTypeCode,jdbcType=SMALLINT} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询FuneralDead列表
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String listFuneralDead(@Param("entity") FuneralDeadEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,business_code,dead_name,dead_gender_code,dead_nation_code,dead_age_type_code,dead_age,birth_date,certificate_type_code,certificate_no,dead_name_unison,dead_name_abbr,death_date,death_cause,ash_handle_type_code,cremation_type_code,remains_state_code,country_code,province_id,city_id,county_id,town_id,village_id,province_city_county_full_name,household_registration_place,as_local,before_death_address,benefit_district_code,exemption_type_code,death_certificate_no,death_certificate_unit,funeral_certificate_unit,transport_place,as_arrived,arrived_time,negotiator_user_id,remark,whereabout_type_code,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" funeral_dead ");

                if (entity.getBusinessCode() != null) {
                    WHERE(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                }

                if (entity.getDeadName() != null) {
                    WHERE(" dead_name = #{entity.deadName,jdbcType=VARCHAR} ");
                }

                if (entity.getDeadGenderCode() != null) {
                    WHERE(" dead_gender_code = #{entity.deadGenderCode,jdbcType=SMALLINT} ");
                }

                if (entity.getDeadNationCode() != null) {
                    WHERE(" dead_nation_code = #{entity.deadNationCode,jdbcType=SMALLINT} ");
                }

                if (entity.getDeadAgeTypeCode() != null) {
                    WHERE(" dead_age_type_code = #{entity.deadAgeTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getDeadAge() != null) {
                    WHERE(" dead_age = #{entity.deadAge,jdbcType=VARCHAR} ");
                }

                if (entity.getBirthDate() != null) {
                    WHERE(" birth_date = #{entity.birthDate,jdbcType=DATE} ");
                }

                if (entity.getCertificateTypeCode() != null) {
                    WHERE(" certificate_type_code = #{entity.certificateTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getCertificateNo() != null) {
                    WHERE(" certificate_no = #{entity.certificateNo,jdbcType=VARCHAR} ");
                }

                if (entity.getDeadNameUnison() != null) {
                    WHERE(" dead_name_unison = #{entity.deadNameUnison,jdbcType=VARCHAR} ");
                }

                if (entity.getDeadNameAbbr() != null) {
                    WHERE(" dead_name_abbr = #{entity.deadNameAbbr,jdbcType=VARCHAR} ");
                }

                if (entity.getDeathDate() != null) {
                    WHERE(" death_date = #{entity.deathDate,jdbcType=DATE} ");
                }

                if (entity.getDeathCause() != null) {
                    WHERE(" death_cause = #{entity.deathCause,jdbcType=VARCHAR} ");
                }

                if (entity.getAshHandleTypeCode() != null) {
                    WHERE(" ash_handle_type_code = #{entity.ashHandleTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getCremationTypeCode() != null) {
                    WHERE(" cremation_type_code = #{entity.cremationTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getRemainsStateCode() != null) {
                    WHERE(" remains_state_code = #{entity.remainsStateCode,jdbcType=SMALLINT} ");
                }

                if (entity.getCountryCode() != null) {
                    WHERE(" country_code = #{entity.countryCode,jdbcType=SMALLINT} ");
                }

                if (entity.getProvinceId() != null) {
                    WHERE(" province_id = #{entity.provinceId,jdbcType=INTEGER} ");
                }

                if (entity.getCityId() != null) {
                    WHERE(" city_id = #{entity.cityId,jdbcType=INTEGER} ");
                }

                if (entity.getCountyId() != null) {
                    WHERE(" county_id = #{entity.countyId,jdbcType=INTEGER} ");
                }

                if (entity.getTownId() != null) {
                    WHERE(" town_id = #{entity.townId,jdbcType=INTEGER} ");
                }

                if (entity.getVillageId() != null) {
                    WHERE(" village_id = #{entity.villageId,jdbcType=INTEGER} ");
                }

                if (entity.getProvinceCityCountyFullName() != null) {
                    WHERE(" province_city_county_full_name = #{entity.provinceCityCountyFullName,jdbcType=VARCHAR} ");
                }

                if (entity.getHouseholdRegistrationPlace() != null) {
                    WHERE(" household_registration_place = #{entity.householdRegistrationPlace,jdbcType=VARCHAR} ");
                }

                if (entity.getAsLocal() != null) {
                    WHERE(" as_local = #{entity.asLocal,jdbcType=TINYINT} ");
                }

                if (entity.getBeforeDeathAddress() != null) {
                    WHERE(" before_death_address = #{entity.beforeDeathAddress,jdbcType=VARCHAR} ");
                }

                if (entity.getBenefitDistrictCode() != null) {
                    WHERE(" benefit_district_code = #{entity.benefitDistrictCode,jdbcType=SMALLINT} ");
                }

                if (entity.getExemptionTypeCode() != null) {
                    WHERE(" exemption_type_code = #{entity.exemptionTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getDeathCertificateNo() != null) {
                    WHERE(" death_certificate_no = #{entity.deathCertificateNo,jdbcType=VARCHAR} ");
                }

                if (entity.getDeathCertificateUnit() != null) {
                    WHERE(" death_certificate_unit = #{entity.deathCertificateUnit,jdbcType=VARCHAR} ");
                }

                if (entity.getFuneralCertificateUnit() != null) {
                    WHERE(" funeral_certificate_unit = #{entity.funeralCertificateUnit,jdbcType=VARCHAR} ");
                }

                if (entity.getTransportPlace() != null) {
                    WHERE(" transport_place = #{entity.transportPlace,jdbcType=VARCHAR} ");
                }

                if (entity.getAsArrived() != null) {
                    WHERE(" as_arrived = #{entity.asArrived,jdbcType=TINYINT} ");
                }

                if (entity.getArrivedTime() != null) {
                    WHERE(" arrived_time = #{entity.arrivedTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getNegotiatorUserId() != null) {
                    WHERE(" negotiator_user_id = #{entity.negotiatorUserId,jdbcType=INTEGER} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getWhereaboutTypeCode() != null) {
                    WHERE(" whereabout_type_code = #{entity.whereaboutTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}